package com.yunxi.controller.dealer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.dealer.pojo.AreaManagerVO;
import com.yunxi.dealer.service.AreaManagerDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2019-07-23
 */
@RestController
@RequestMapping("/admin/areamanager")
@Api(tags = "pms:areamanager", description = "接口")
public class AreaManagerController {
   private static final Logger logger = LoggerFactory.getLogger(AreaManagerController.class);

   @Autowired
   AreaManagerDubboService areaManagerDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(AreaManagerVO areaManagerVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.findPageByVO(areaManagerVO, pageNum, pageSize));
   }

   @GetMapping("/pageByUserCode")
   @ApiOperation(value = "查询小区经理的管辖城市")
   public ApiResult pageByUserCode(AreaManagerVO areaManagerVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.pageByUserCode(areaManagerVO, pageNum, pageSize));
   }

   @GetMapping("/pageCityNotExisit")
   @ApiOperation(value = "查询小区经理的未管辖城市")
   public ApiResult pageCityNotExisit(AreaManagerVO areaManagerVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.pageCityNotExisit(areaManagerVO, pageNum, pageSize));
   }

   @GetMapping("/listByUserCode")
   @ApiOperation(value = "查询小区经理的管辖城市")
   public ApiResult listByUserCode(AreaManagerVO areaManagerVO) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.listByUserCode(areaManagerVO));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询列表")
   public ApiResult list(AreaManagerVO areaManagerVO) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.listByVo(areaManagerVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(AreaManagerVO areaManagerVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(areaManagerDubboService.getById(areaManagerVO.getMainId()));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody AreaManagerVO areaManagerVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      areaManagerDubboService.saveOrUpdate(areaManagerVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<AreaManagerVO> areaManagerVOList) throws Exception {
      areaManagerDubboService.removeByListVo(areaManagerVOList);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/delByUserCode")
   @ApiOperation(value = "根据账号删除")
   public ApiResult delByUserCode(@RequestBody AreaManagerVO areaManagerVO) throws Exception {
      areaManagerDubboService.delByUserCode(areaManagerVO.getUserCode());
      return ResponseUtil.ok("success");
   }

//   @PostMapping("/changeAreaManager")
//   @ApiOperation(value = "更换大区经理")
//   public ApiResult changeAreaManager(@RequestBody AreaManagerVO areaManagerVO) throws Exception {
//      areaManagerDubboService.changeAreaManager(areaManagerVO);
//      return ResponseUtil.ok();
//   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(areaManagerDubboService.findMapByList(params));
}*/
}
